package com.cpfmat.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.baomidou.mybatisplus.plugins.Page;
import com.cpfmat.common.Contains;
import com.cpfmat.entity.OtherUser;
import com.cpfmat.service.IOtherUserService;

@Controller
public class OtherUserManageController {

	

	@Autowired
	private IOtherUserService otherUserService;

	@RequestMapping(path = "/manage/searchUser")
	public ModelAndView searchUser(@RequestParam(defaultValue = "1", name = "pageNum") int pageNum,
			@RequestParam(required = false, name = "userName") String userName, HttpServletRequest request) {

		ModelAndView view = new ModelAndView("/manage/otherUser/otherUserAjaxtr");
		Page<OtherUser> page = this.queryList(pageNum, Contains.PAGE_SIZE, userName);
		view.addObject("page", page);
		return view;

	}

	@RequestMapping(path = "/manage/userList")
	public ModelAndView init() {
		ModelAndView view = new ModelAndView("/manage/otherUser/otherUserList");
		return view;
	}

	@RequestMapping(path = "/manage/userDel")
	@ResponseBody
	public boolean del(String userId) {
		try {
			OtherUser user = new OtherUser();
			user.setSqlId(userId);
			user.setDelFlag(1);

			otherUserService.updateById(user);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return false;
		}
	}

	private Page<OtherUser> queryList(int pageNum, int pageSize, String userName) {
		return otherUserService.getcontentByUser(userName, pageNum, pageSize);
	}
}
